/*
 * This file is part of aKoustiK.

 * aKoustiK is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.

 * aKoustiK is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with aKoustiK.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <KIcon>
#include <KLocale>

#include <kore.h>
#include <ui/player/repeataction.h>

RepeatAction::RepeatAction(QObject *parent) : KAction(parent) {
    playerRepeat = Kore::instance().player()->repeat();
    setupProperties();
    connect(this, SIGNAL(triggered()), SLOT(internalTriggerSlot()));
    connect(this, SIGNAL(toggleRepeat(bool)), Kore::instance().player(), SLOT(repeat(bool)));
}

RepeatAction::~RepeatAction() {
}

void RepeatAction::internalTriggerSlot() {
    if (playerRepeat) {
        playerRepeat = false;
    }
    else {
        playerRepeat = true;
    }
    setupProperties();
    emit toggleRepeat(playerRepeat);
}

void RepeatAction::setupProperties() {
    if (playerRepeat) {
        setIcon(KIcon("view-refresh"));
        setToolTip(i18n("Repeat: <b>%1</b>", "on"));
    }
    else {
        setIcon(KIcon("go-last-view"));
        setToolTip(i18n("Repeat: <b>%1</b>", "off"));
    }
}
